package com.wlr.study.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 两数之和
 *
 * @author HustleLr
 * @version 1.0.0
 * @date 2024/1/17 15:44
 * @describe LeetCode1
 */
public class LeetCode1 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }
        for (int i = 0; i < nums.length; i++) {
            int other = target - nums[i];
            if (map.containsKey(other) && map.get(other) != i) {
                return new int[]{i, map.get(other)};
            }
        }
        return null;
    }
}
